<?php
include("../db_connect.php");
include("../class/objNameTrade.php");
$obj = new objName();
$on = true;

$name = "";
$brand = "";
$model = "";
$fname = "";
$lname = ""; 
$from = "car";
$find[] = ',';
$replace[] = ' ';
if(isset($_GET['name'])){
	$name = $_GET['name'];
}

if(isset($_GET['brand'])){
	$brand = $_GET['brand'];
	
	if($brand == "all"){
		$brand= "";
	}else{
		$brand = $obj->get_product_brand($brand);
	}	
}

if(isset($_GET['model'])){
	$model = $_GET['model'];
	$model = str_replace($find, $replace, $_GET['model']);
	
}

if(isset($_GET['fname'])){
	$fname = mysql_real_escape_string(htmlentities(trim( $_GET['fname'])));
	$fname = str_replace($find, $replace, $fname);
	
}

if(isset($_GET['lname'])){
	$lname = mysql_real_escape_string(htmlentities(trim( $_GET['lname'])));
	$lname = str_replace($find, $replace, $lname);
}


$sql = "SELECT * FROM tbltradein";
$sql .= " WHERE brand like '".$brand."%' and addoff = 'guest' " ; 

if($name != "" || $name != 0){
$sql .= " AND types like '".$name."%'"; 
}

else if($model != ""){
	if(!empty($model) && $model != 'null' ){
			$sql .= " AND model = '".$model."'"; 
	}
}

if($fname != ""){
$sql .= " AND fname like '".$fname."%'"; 

}
if($lname != "" ){
$sql .= " AND lname like '".$lname."%'"; 
}



$sql .=" and addoff != '1' ORDER BY display,id DESC";

//echo $sql;
$result = mysql_query($sql);
$i = mysql_num_rows($result);

if($i<=0){
echo '<div style="margin-top:10px;"><h3 style="color:white;">No Item Found</h3></div>';
}
else{

	echo "<form id='guestcheckall'>";
	echo "<table id='itemRequestTrade'  border='0' >
	<thead>
	<tr>
		<th id='tbl_head_color' style=' width:50px; background-color:#ba3e3f; text-align:center;'> <input type='checkbox' name='checkall' onclick='guest_check()';/></th>
		<th id='tbl_head_color' style='width:1px; background-color:#ba3e3f; '>Status</th>
		<th id='tbl_head_color' style='width:1px; background-color:#ba3e3f; '>Title</th>
		<th id='tbl_head_color' style='width:200; background-color:#ba3e3f; '>Model</th>
		<th id='tbl_head_color' style='width:700px; background-color:#ba3e3f; '>Description</th>
		</tr>
	</thead>";


	while($row= mysql_fetch_array($result)){
		 echo "<tbody id='itemRequestchange'>";
			$o = $obj->displayimg($row['filename'],true);
		    $n = $obj->get_profile_name($row['addoff']);
			
			if($row['display'] == 1){
				$status="Displaying"; echo "<tr class='even'>";
			}
			else{
				$status="Not Displaying"; echo "<tr class='odd' style='background-color:#C8C8BD'>";
			}
			echo "<td style='text-align:center;' valign='top'><input type='checkbox' class='cd' name='checkbox' value='".$row['id']."'></td>";
			echo "<td valign='top'>" . $status . "</td>";
			echo "<td valign='top' width='100px'><img id='' width='215' height='130' src='images/vehicles/$o'><div>Posted by:<a href='#' style='color:red;' > $n </a>";
			echo	"<p>ItemName:".$row['name']."</br> Time posted:".$row['timepost']."</br><a href='preview.php?from=admin.&pageid=".$row['id']."' style='color:red'>Preview</a>
			|<a href='#' onclick='delete_item2(".$row['id'].")' style='color:red'>Delete</a>
			</p>";
			echo "</div></td>";
			echo"<td valign='top' width='100px'><div width='100'>Brand:" .$row['brand'] ."</br>Model: ".$row['model'] ."</br>Trans: ".$row['transmission']."</div></td>";
			echo"<td valign='top'><p align='justify'>" .$row['description']."</p></td>";
			 
		
		  echo "</tr>";
	}
	echo "</tbody></table></form>";


}	

?>